<?php
namespace Admin\Controller;
use Think\Controller;
class BaseController extends Controller {
	protected function _initialize(){
		if($_SESSION['admin']['is_login']!=1){
			$this->error('登陆已超时,请重新登陆',U('/admin/login'));
		}
		
		$this->assign('session',$_SESSION);
	}
	
	
	//导航
	public function getBread($bread){
		if($bread){
			$this->assign('bread',$bread);
			return $this->fetch('Base_bread');
		}else{
			$this->error('请传入面包导航！');
		}
	}
	
	//封装分页类
	public function getPage($count,$psize,$loader,$loadername,$searchname,$map,$pages='page'){
		if(!$count && !$psize || !$loader || !$loadername){
			die('缺少分页参数!');
		}
		$page = new \bb\Pagecms($count,$psize);// 实例化分页类 传入总记录数和每页显示的记录数
		$page->setConfig('loader',$loader);
		$page->setConfig('loadername',$loadername);
		//绑定前端form搜索表单ID,默认为#Joel-search
		if($searchname){
			$page->setConfig('searchname',$searchname);
		}		
		if($map){
			foreach($map as $key=>$val) {
    			$page->parameter[$key]   =   urlencode($val);
			}
		}
		$show = $page->show();// 分页显示输出
		$this->assign($pages,$show);
		return true;	
	}
	//==================
	
	//获取单张图片
	public function getPic($id){
		$m=M('weixin_upload_img');
		$map['id']=$id;
		$list=$m->where($map)->find();
		if($list){
			$list['imgurl']="/Upload/".$list['savepath'].$list['savename'];
		}
		return $list?$list:"";
	}
	//获取图集合
	public function getAlbum($ids){
		$m=M('weixin_upload_img');
		$map['id']=array('in',$ids);
		$list=$m->where($map)->select();
		foreach($list as $k=>$v){
			$list[$k]['imgurl']="/Upload/".$list[$k]['savepath'].$list[$k]['savename'];			
		}		
		return $list?$list:"";
	}
	
}